<template>
  <div>
    <div class="icon" @click="open"><i class="el-icon-setting"></i></div>
    <el-dialog
      title="机械臂设置"
      :visible.sync="settingDialogVisible"
      center
      width="20%"
      @open="open"
    >
      <div class="settingContent">
        <div class="item">
          <div class="title">主机IP：</div>
          <div class="setting_option">
            <el-input
              v-model="ports.reproduction.hostAddress"
              placeholder=""
              type="url"
            ></el-input>
          </div>
        </div>
        <div class="item">
          <div class="title">端口：</div>
          <div class="setting_option">
            <el-input
              v-model="ports.reproduction.port"
              placeholder=""
              type="url"
            ></el-input>
          </div>
        </div>
        <div class="item">
          <div class="title">串口：</div>
          <div class="setting_option">
            <el-select
              v-model="ports.reproduction.serialPort"
              placeholder="请选择串口"
            >
              <el-option
                v-for="(item, index) in ports.serialPort"
                :key="index"
                :label="item"
                :value="item"
              >
              </el-option>
            </el-select>
          </div>
        </div>
        <div class="footBottom">
          <div class="item">
            <el-button type="success" @click="connection">一键链接</el-button>
          </div>
          <div class="item">
            <el-button type="danger" @click="disconnect">一键断开</el-button>
          </div>
        </div>

        <!-- <span slot="footer" class="dialog-footer">
          <el-button @click="maskShow = false">取消</el-button>
          <el-button type="primary">保存</el-button>
        </span> -->
      </div>
    </el-dialog>
  </div>
</template>

<script>
import flyAPi from "@/api/fly.js";
export default {
  name: "MechanicalSetting",
  data() {
    return {
      settingDialogVisible: false,
      ports: {
        reproduction: {},
      },
    };
  },
  computed: {},
  watch: {},
  mounted() {},
  methods: {
    open() {
      this.settingDialogVisible = true;
      flyAPi.scanSerialPort().then((res) => {
        if (res.data.code == 200) {
          this.ports = res.data.data;
        }
      });
    },
    connection() {
      flyAPi.connection(this.ports.reproduction).then((res) => {
        if (res.data.code == 200) {
          this.$message.success("连接成功");
        } else {
          this.$modal.msgError(res.data.msg);
        }
      });
    },
    disconnect() {
      flyAPi.disconnect().then((res) => {
        if (res.data.code == 200) {
          this.$message.success("断开成功");
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.icon {
  font-size: 24px;
}
.settingContent {
  width: 100%;
  display: flex;
  flex-flow: column;
  justify-content: flex-start;
  align-items: flex-start;
  gap: 10px;
  .item {
    height: 40px;
    display: flex;
    flex-flow: row;
    justify-content: flex-start;
    align-items: center;
    .title {
      width: 60px;
      white-space: nowrap;
    }
    .setting_option {
      display: flex;
      flex-flow: row;
      justify-content: flex-start;
      align-items: center;
      &::v-deep .el-input__inner {
        width: 100%;
        height: 34px;
        padding-left: 20px;
      }
    }
  }
}
.footBottom {
  width: 100%;
  display: flex;
  flex-flow: row;
  justify-content: space-between;
  align-items: center;
}
</style>
